#include <libpub.h>

#define DELAY_10MS      10
#define DELAY_100MS     100
#define DELAY_1000MS    1000
#define DELAY_2000MS    2000

extern "C"{
void backlight_open();
int BackLight_SetBrightness(void *pCxt, int bright_val);
void msleep(unsigned int ms);
int Do_InitLcd(void);
void Display_Logo();
}

void backlight_close()
{
    BackLight_SetBrightness(0, 0);
}

int nBrightTable[11][2]={
    {30,  30},  //0
    {50,  30},  //1
    {80,  30},  //2
    {120, 30},  //3
    {185, 30},  //4
    {250, 30},  //5 default
    {315, 30},  //6
    {380, 40},  //7
    {420, 40},  //8
    {460, 40},  //9
    {500, 50},  //10
};

static int Do_Test_LcdBacklight_Auto(void)
{
    TOUT(1, 1, printf("\n Do_Test_LcdBacklight_Auto():\n"));

    //test light close and open
    backlight_close();
    msleep(DELAY_2000MS);
    backlight_open();
    msleep(DELAY_2000MS);

    //test light all level
    int l = 0;
    for(l = 0; l < 11; l++){
        BackLight_SetBrightness(0, nBrightTable[l][0]);
        msleep(DELAY_2000MS);
    }

    backlight_open();//restore default

    return 0;
}

int Do_Test_LcdBacklight(char *param)
{
    TOUT(1,1,printf("\n Do_Test_LcdBacklight(%s):\n", param));

    Do_InitLcd();
    Display_Logo();

    int bright_val = 0;

    if (*param) {
        param = Bo_ParseInteger(param, (unsigned long *) &bright_val);
        TOUT(1, 1, printf("\n Light value = (%d):\n", bright_val));
        BackLight_SetBrightness(0, bright_val);
   }
   else {
        Do_Test_LcdBacklight_Auto();
   }
   return 0;
}
